<?php
    $group_id = isset($_SESSION['groupid']) ? $_SESSION['groupid'] : -1;
    if ($group_id == 1 || $group_id == 4) $can_edit_price = true;
    else $can_edit_price = false;
?>
<?php $this->loadHelper('common'); ?>
<div id="manager">
        <div>
        <div id="bg-title1"><img src="/images/bg-title1.jpg" alt="" /></div>
        <div id="bg-title2"><img src="/images/icon-title.jpg" style="margin-right:8px;" alt="" />Cập nhật thông tin video</div>
        <div id="bg-title3"><img src="/images/bg-title3.jpg" alt="" /></div>
        <div class="clearfloat"></div>
        </div>        
    <div id="content">
        <div class="area-button">
            <div style="margin-left:40%">
                <a href="javascript:;" onclick="document.frmEditVideo.submit();return false;" class="button">Cập nhật</a>
            <a href="javascript:;" onclick="deleteObject('video', <?php echo $video['id']; ?>);return false;" class="button">Xóa</a>
            </div>
        </div>

        <div class="area-content">
            <div class="column1">
                <?php echo renderPlayer($video); ?>
            </div>

            <div class="column2">
                <form name="frmEditVideo" method="post" action="/video/edit?id=<?php echo $video['id']; ?>">
                    <input type="hidden" value="" id="thumbnail" name="thumbnail"/>
                    <?php if ($can_edit_price): ?>
                    <div class="form">
                        Đăng bởi: <b><?php echo $inforClip['owner']; ?></b><br/>
                        <?php if($inforClip['subcp_name']): ?>
                        Đối tác: <b><?php echo $inforClip['subcp_name']; ?></b><br/>
                        <?php endif; ?>
                        <?php if($inforClip['approver']): ?>
                        Duyệt bởi: <b><?php echo $inforClip['approver']; ?></b><br/>
                        <?php endif; ?>
                    </div>
                    <div class="form">
                        Giá xem<br />
                        <div><input type="text" name="price" style="width:400px" class="style-form" value="<?php echo isset($_POST['price']) ? $_POST['price'] : ''?>" READONLY />
                            <?php if (isset($error['price'])): ?>
                            <div class="error"><?php echo $error['price']; ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="form">
                        Giá tải<br />
                        <div><input type="text" name="download_price" style="width:400px" class="style-form" value="<?php echo isset($_POST['download_price']) ? $_POST['download_price'] : ''?>" READONLY />
                            <?php if (isset($error['download_price'])): ?>
                            <div class="error"><?php echo $error['download_price']; ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <?php endif; ?>
                    <div class="form">
                        Tiêu đề<br />
                        <div><input type="text" name="title" style="width:400px" class="style-form" value="<?php echo isset($_POST['title']) ? htmlentities($_POST['title'], ENT_QUOTES, "UTF-8") : ''?>" />
                            <?php if (isset($error['title'])): ?>
                            <div class="error"><?php echo $error['title']; ?></div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="form">
                        Mô tả<br />
                        <div>
                            <textarea name="description" id="description" style="width:400px" rows="10"><?php echo isset($_POST['description']) ? $_POST['description'] : ''; ?></textarea>
                            <?php if (isset($error['description'])): ?>
                            <div class="error"><?php echo $error['description']; ?></div>
                            <?php endif; ?>
                        </div>
                        <div class="clearfloat"></div>
                    </div>

                    <div class="form">
                        Tag<br />
                        <div><input type="text" name="tag" style="width:400px" class="style-form" value="<?php echo isset($_POST['tag']) ? $_POST['tag'] : ''?>"/>
                            <?php if (isset($error['tag'])): ?>
                            <div class="error"><?php echo $error['tag']; ?></div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="form">
                        Chuyên mục<br />
                        <div>
                            <?php echo $this->renderElement('category.select.tpl.php', array('cats' => $cats)); ?>
                        </div>
                        <div class="clearfloat"></div>
                    </div>
                    <?php if($subCpList): ?>
                    <div class="form">
                        CP con<br />
                        <div>
                            <select name="subcp_id" style="width:400px">
                                <option value="0">Không có</option>
                                <?php foreach ($subCpList as $item): ?>
                                <option<?php echo ($item['id'] == $_POST['subcp_id']) ? ' selected' : '';?> value="<?php echo $item['id']; ?>"><?php echo $item['fullname']; ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="clearfloat"></div>
                    </div>
                    <?php endif; ?>
                    <div class="form">
                        Hình nền hiện tại<br />
                        <div class="clearfloat"></div>
                    </div>
                    <div class="form">
                        <a class="thumb" style="position:relative;top:10px;left:100px">
                            <img alt="" src="<?php echo makeVideoThumbnailUrl($video['id']); ?>" title="hinh nen" width="120" height="90" />
                        </a>
                    </div>
                </form>

            </div>
            <div class="clearfloat"></div>
            <br/>
            <div>
                <div class="form">
                    Chọn hình nền
                </div>
                <div class="form">
                    <style type="text/css">
                        .thumb-list {padding:0 50px}
                        .thumb, .thumb-item {float:left;background:#FFF; border:1px solid #DDD; margin:5px; padding:5px; width:120px; height:90px}
                        .thumb {background:#EAF4F7;border-color:#B0BFCC}
                    </style>
                    <div class="thumb-list">
                        <?php foreach ($thumbs as $index => $thumb): ?>
                        <a class="thumb-item" href="javascript:void(0);">
                            <img src="<?php echo $thumb['url'] ?>" name="<?php echo $thumb['name'] ?>" border="0" width="120" height="90" alt="" />
                        </a>
                        <?php endforeach; ?>
                    </div>
                </div>
                <div class="clearfloat"></div>
            </div>
        </div>

        <div class="area-button">
            <div style="margin-left:40%">
                <a href="javascript:;" onclick="document.frmEditVideo.submit();" class="button">Cập nhật</a>
            <a href="javascript:;" onclick="deleteObject('video', <?php echo $video['id']; ?>);" class="button">Xóa</a>
            </div>
        </div>
    </div>
</div>
<div class="clearfloat"></div>
<script type="text/javascript">
    $(function(){
        $("#description").htmlarea();
    });
    $('#content .thumb-item').click(function(){
        $(this).css('background-color', $('#content .thumb').css('background-color')).css('border-color', $('#content .thumb').css('border-left-color'));
        $(this).siblings().css('background-color', '#FFF').css('border-color', '#DDD');
        $("#content .thumb").html($(this).html());

        $("#thumbnail").val($(this).find("img").attr('name'));
    });
</script>